var gulp=require("gulp"),
	webserver=require("gulp-webserver"),
	livereload=require("gulp-livereload"),
	sass=require("gulp-ruby-sass"),
	rename=require("gulp-rename"),
	uglify=require("gulp-uglify"),
	sourcemap=require("gulp-sourcemaps"),
	tinypng=require("gulp-tinypng");

	gulp.task("webserver",function(){
		gulp.src("dest")
		.pipe(webserver({
			livereload:true,
			open:true
		}))
	})

	gulp.task("html",function(){
		return gulp.src("src/**/*.html")
		.pipe(gulp.dest("dest"));
	})

	gulp.task("sass",function(){
		return sass("src/sass/*.scss",{style:"compressed"})
		.on("error",function(err){
			console.log(err);
		})
		.pipe(gulp.dest("dest/css"))
	})

	gulp.task("js",function(){
		return gulp.src("src/js/*.js")
		.pipe(sourcemap.init())
		.pipe(uglify())
		.pipe(rename({suffix:".min"}))
		.pipe(sourcemap.write("map"))
		.pipe(gulp.dest("dest/js"));
	})


	gulp.task("tinypng",function(){
		return gulp.src("src/images/*.jpg")
		
		.pipe(gulp.dest("dest/images"))
	})

	gulp.task("watch",function(){
		gulp.watch("src/**/*.html",["html"])
		gulp.watch("src/sass/*.scss",["sass"])
		gulp.watch("src/js/*.js",["js"])
		gulp.watch("src/images/*.jpg",["images"])
	})

	gulp.task("default",["webserver","html","sass","tinypng","watch"])